package com.bw.controller;

import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.bw.service.foodservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class foodcontroller {

    @Autowired(required = false)
    foodservice foodservice1;


//    {
//        "status": 0,
//            "msg": "",
//            "data": 1201057.979351366
//    }
    //翻牌器
    @RequestMapping("/show")
    public  Object show(){
        List<Map> list = foodservice1.show();//从数据库里拿数据


        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");
        jsonObject.put("data",list.get(0).get("aa"));


        return jsonObject;
    }



//    {
//        "status": 0,
//            "msg": "",
//            "data": [
//        {
//            "name": "PC",
//                "value": 97,
//                "url": "http://www.baidu.com"
//        },
//        {
//            "name": "iOS",
//                "value": 50,
//                "url": "http://www.baidu.com"
//        },
    //饼图
    @RequestMapping("/show1")
    public  Object show1(){
        List<Map> list = foodservice1.show1();//从数据库里拿数据


        JSONObject jsonObject = new JSONObject();
        jsonObject.put("status",0);
        jsonObject.put("msg","");

        JSONArray objects = new JSONArray();
        for (Map map : list) {
            JSONObject jsonObject1 = new JSONObject();
            jsonObject1.put("name",map.get("bb"));
            jsonObject1.put("value",map.get("cc"));
            objects.add(jsonObject1);
        }

        jsonObject.put("data",objects);


        return jsonObject;
    }
}
